package com.fly.vo;



import com.fly.persistence.DataEntity;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Fly
 * @Description
 * @Date Created in 15:29 2017/11/7
 * @Modified by
 */
public class Valid<T extends DataEntity<T>> {

    /**
     * 校验
     * @param entity
     * @param id
     * @return
     */
    public Map<String, Object> valid(T entity, Long id){
        boolean valid = false;
        //id为空为新增
        if (id == null) {
            if (entity == null) {
                valid = true;
            }
        } else {//id不为空为修改的时候
            if (entity == null) {
                valid = true;
            } else if (entity.getId().equals(id)) {
                valid = true;
            }
        }
        Map<String, Object> map = new HashMap<>();
        map.put("valid", valid);
        return map;
    }
}
